package hjj.dwr;

import java.util.ArrayList;
import java.util.List;

import dao.impl.DeptDAOImpl;
import dao.impl.DutyDAOImpl;
import dao.impl.dept_duty_empDAOImpl;

import model.Dept;
import model.Duty;
import model.dept_duty_emp;

public class DeptDutyDwr {
	public List<Dept> getAllDept(){
		DeptDAOImpl ddi=new DeptDAOImpl();
		List<Dept> list=ddi.getALLDept();
		return list;
	}
	public List<Duty> getAllDuty(){
		DutyDAOImpl ddi=new DutyDAOImpl();
		List<Duty> list=ddi.getAllDuty();
		return list;
	}
	
	public boolean addDeptDuty(String deptname,String dutyname,String num){
		boolean flag=false;
		DeptDAOImpl ddi=new DeptDAOImpl();
		DutyDAOImpl ddi2=new DutyDAOImpl();
		dept_duty_emp dde=new dept_duty_emp();
		dept_duty_empDAOImpl ddedi=new dept_duty_empDAOImpl();
		try{
			int deptid=Integer.parseInt(deptname);
			int dutyid=Integer.parseInt(dutyname);
			Dept dept=ddi.getDeptById(deptid);
			Duty duty=ddi2.getDutyById(dutyid);
			int empnum=Integer.parseInt(num);
			dde.setDept(dept);
			dde.setDuty(duty);
			dde.setEmpnum(empnum);
			flag=ddedi.addDeptDuty(dde);
		}catch (Exception e) {
			
		}
		return flag;
	}
	
	public boolean updateDeptDuty(String deptname,String dutyname,String num){
		boolean flag=false;
		DeptDAOImpl ddi=new DeptDAOImpl();
		DutyDAOImpl ddi2=new DutyDAOImpl();
		dept_duty_emp dde=new dept_duty_emp();
		dept_duty_empDAOImpl ddedi=new dept_duty_empDAOImpl();
		try{
			Dept dept=ddi.getDeptByName(deptname);
			Duty duty=ddi2.getDutyByName(dutyname);
			int empnum=Integer.parseInt(num);
			dde.setDept(dept);
			dde.setDuty(duty);
			dde.setEmpnum(empnum);
			flag=ddedi.updateDeptDuty(dde);
		}catch (Exception e) {
			
		}
		return flag;
	}
	
	public boolean deleteDeptDuty(String deptname,String dutyname){
		boolean flag=false;
		DeptDAOImpl ddi=new DeptDAOImpl();
		DutyDAOImpl ddi2=new DutyDAOImpl();
		dept_duty_emp dde=new dept_duty_emp();
		dept_duty_empDAOImpl ddedi=new dept_duty_empDAOImpl();
		try{
			Dept dept=ddi.getDeptByName(deptname);
			Duty duty=ddi2.getDutyByName(dutyname);
			dde.setDept(dept);
			dde.setDuty(duty);
			flag=ddedi.deleteDeptDuty(dde);
		}catch (Exception e) {
			
		}
		return flag;
	}
	
}
